<?php
namespace app\index\model;

use app\common\model\SuperModel;

class Role extends SuperModel {

	protected $connection = 'db_config_dragon';

	/**
	 * 列表(主键列表，条件数组，闭包查询)
	 *
	 * @param    array $param 查询条件
	 * @return   void
	 */
	public function doList($param = null) {

		try {

			//查询数据
			$result = self::all($param);
			$rows = [];

			foreach ($result as $data) {
				$item = $data->getData();
				array_push($rows, $item);
			}

			//返回结果
			$res = array();

			$total = count($rows);

			if ($total > 0) {
				$res['rows'] = $rows;
				$res['total'] = $total;
			} else {
				$res['total'] = 0;
				$res['rows'] = array();
			}

			return ($res);

		} catch (\Exception $e) {
			throw new \think\Exception('异常消息:' . $e->getMessage());
		}
	}

    /**
     * 更新数据模型
     *
     * @return   void
     */
    public function doUpdateByArr($param)
    {

        try {

            //过滤请求数组中非数据表数据
            $res = self::allowField(true)
                ->isUpdate(true)
                ->save($param, ['id' => $param['id']]);

            return ($res);

        } catch (\Exception $e) {
            throw new \think\Exception('异常消息:' . $e->getMessage());
        }
    }
}
